#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define all(x) begin(x),end(x)
typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> iset;
void solve(){
const long long MOD=998244353;
long long n;
cin>>n;
map<int,long long> m;
vector<vector<long long>> a;
for(int i=0;i<n;i++){
int k;
cin>>k;
a.push_back(vector<long long>(k));
while(k--){
long long x;
cin>>x;
m[x]++;
a[i][k]=x;
}
}
auto pow=[&](auto&&pow,long long x,long long y)->long long
{
if(y==0)return 1;
long long sol=pow(pow,x,y/2);
sol*=sol;
sol%=MOD;
if(y%2)sol*=x;
sol%=MOD;
return sol;
};
long long val=0;
for(auto&as:a){
for(auto i:as){
long long can=1;
can*=pow(pow,n,MOD-2);
can%=MOD;
can*=pow(pow,n,MOD-2);
can%=MOD;
can*=pow(pow,as.size(),MOD-2);
can%=MOD;
can*=m[i];
can%=MOD;
val+=can;
val%=MOD;
}
}
long long sol=val;
sol%=MOD;
cout<<sol<<'\n';
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int numberOfTests=1;
//cin>>numberOfTests;
while(numberOfTests--){
solve();
}
}
1395A - Boboniu Likes to Color Balls | 1637C - Andrew and Stones |
1334B - Middle Class | 260C - Balls and Boxes |
1554A - Cherry | 11B - Jumping Jack |
716A - Crazy Computer | 644A - Parliament of Berland |
1657C - Bracket Sequence Deletion | 1657B - XY Sequence |
1009A - Game Shopping | 1657A - Integer Moves |
230B - T-primes | 630A - Again Twenty Five |
1234D - Distinct Characters Queries | 1183A - Nearest Interesting Number |
1009E - Intercity Travelling | 1637B - MEX and Array |
224A - Parallelepiped | 964A - Splits |
1615A - Closing The Gap | 4C - Registration System |
1321A - Contest for Robots | 1451A - Subtract or Divide |
1B - Spreadsheet | 1177A - Digits Sequence (Easy Edition) |
1579A - Casimir's String Solitaire | 287B - Pipeline |
510A - Fox And Snake | 1520B - Ordinary Numbers |